﻿using UnityEngine;
using System.Collections;

public class Target : MonoBehaviour
{
	public float Speed 		= 1.0f;

	public int Alpha 		{ get; private set; }

	private int m_Life 		= 1;
	private Background m_BGComp = null;

	// Use this for initialization
	public void Setup ( int _Alpha, int _Life, Background _BGComp )
	{
		Alpha 		= _Alpha;

		m_Life 		= _Life;
		m_BGComp 	= _BGComp;
	}

	void Start()
	{
		// Change start alpha
		float NewGrey			= (float)Alpha / (float)m_BGComp.NumAlphaCuts;

		SpriteRenderer SpriteComp = GetComponent< SpriteRenderer >();
		SpriteComp.color 		= new Color( NewGrey, NewGrey, NewGrey );
	}
	
	// Update is called once per frame
	void Update ()
	{
		transform.position = transform.position + 
			Vector3.right * Speed * Time.deltaTime / (float)m_Life;
	}

	void OnMouseDown()
	{
		--m_Life;

		if ( m_Life <= 0 )
		{
			m_BGComp.TargetKilled( this );
			enabled = false;

			Destroy( gameObject );
		}
	}
}
